package com.bs.model;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.bs.enums.OrderStatus;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.Date;
import java.util.List;

/**
 * 订单类
 *
 * @author 琪
 * @since 2025/5/7 19:42
 */
@Data
@ApiModel("订单")
@TableName("bs_order")
public class Order {

    @TableId(type = IdType.ASSIGN_UUID)
    @ApiModelProperty("主键（订单id）")
    private String id;

    @ApiModelProperty(value = "用户id", notes = "订单属于哪个用户的")
    private String userId;

    @ApiModelProperty(value = "用户名称", notes = "数据库不保存, 需要自己填充")
    @TableField(exist = false)
    private String userName;

    @ApiModelProperty("商品列表")
    @TableField(exist = false)
    private List<Item> items;

    @ApiModelProperty("订单状态")
    private OrderStatus status;

    @ApiModelProperty(value = "取餐码", notes = "付款后生成的取餐码，用于取餐")
    private String orderCode;

    @ApiModelProperty("订单最终价格")
    private double totalPrice;

    @ApiModelProperty("订单备注")
    private String remark;

    @ApiModelProperty("创建时间")
    private Date createTime;

    @ApiModelProperty("更新时间")
    private Date updateTime;

    public void appendRemark(String remarkMsg) {
        if (StrUtil.isBlank(this.remark)) {
            this.remark = remarkMsg;
        } else {
            this.remark = this.remark + "\n" + remarkMsg;
        }
    }
}